<?php

/**
 * 订单打印
 */

namespace app\seller\controller;

class OrderPrint extends \app\common\controller\Seller
{

    /**
     * 查看订单
     */
    public function index()
    {
        $order_id = input('order_id/d');
        if ($order_id <= 0) {
            return $this->error('参数错误');
        }
        $order_model = model('Common/Order');
        $condition['order_id'] = $order_id;
        $condition['store_id'] = $this->store_id;
        $order_info = $order_model->getOrderInfo($condition, array('order_common', 'order_goods'));
        if (empty($order_info)) {
            return $this->error('订单信息错误');
        }
        $this->assign('order_info', $order_info);

        //卖家信息
        $model_store = model('Common/Store');
        $store_info = $model_store->getStoreInfoByID($order_info['store_id']);
        $store_info['store_label'] = img_url($store_info['label']);
        $store_info['store_stamp'] = img_url($store_info['store_stamp']);
        $this->assign('store_info', $store_info);

        //订单商品
        $model_order = model('Common/Order');
        $condition = array();
        $condition['order_id'] = $order_id;
        $condition['store_id'] = $this->store_id;
        $goods_new_list = array();
        $goods_all_num = 0;
        $goods_total_price = 0;
        if (!empty($order_info['extend_order_goods'])) {
            $goods_count = count($order_goods_list);
            $i = 1;
            foreach ($order_info['extend_order_goods'] as $k => $v) {
                $v['goods_name'] = mb_substr($v['goods_name'], 0, 100);
                $goods_all_num += $v['goods_num'];
                $v['goods_all_price'] = ncPriceFormat($v['goods_num'] * $v['goods_price']);
                $goods_total_price += $v['goods_all_price'];
                $goods_new_list[ceil($i / 15)][$i] = $v;
                $i++;
            }
        }
        //优惠金额
        $promotion_amount = $goods_total_price - $order_info['goods_amount'];
        //运费
        $order_info['shipping_fee'] = $order_info['shipping_fee'];
        $this->assign('promotion_amount', $promotion_amount);
        $this->assign('goods_all_num', $goods_all_num);
        $this->assign('goods_total_price', ncPriceFormat($goods_total_price));
        $this->assign('goods_list', $goods_new_list);
        return $this->fetch('deliver/print');
    }

}
